package com.mxf.code.controller;

import com.mxf.code.request.EntityDataAddRequest;
import com.mxf.code.request.EntityDataEditRequest;
import com.mxf.code.request.EntityDataPageRequest;
import com.mxf.code.response.EntityDataDetailResponse;
import com.mxf.code.response.EntityDataPageResponse;
import com.mxf.code.service.EntityManagerService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * @author mxf
 * @version 1.0
 * @description: 实体管理
 * @date 2023/5/10
 */
@RestController
@RequestMapping("/entity/manager")
@Api(tags = "实体管理")
public class EntityManagerController {
    @Autowired
    private EntityManagerService entityManagerService;

    @GetMapping("page")
    public List<EntityDataPageResponse> page(@Valid EntityDataPageRequest request) {
        return entityManagerService.pageData(request);
    }

    @PostMapping
    public void saveEntryData(@Valid EntityDataAddRequest request) {
        entityManagerService.saveEntryData(request);
    }

    @PutMapping
    public void modifyEntryData(@Valid EntityDataEditRequest request) {
        entityManagerService.modifyEntryData(request);
    }

    @GetMapping({"{id}"})
    public EntityDataDetailResponse getById(@PathVariable("id") Long id) {
        //return entityManagerService.getDetail(id);
        return null;
    }

    @DeleteMapping
    public void delete(@NotEmpty @RequestBody Long[] ids) {
        entityManagerService.delete(ids);
    }
}
